﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using HIWSystem.Common;
using HIWSystem.Models;

namespace HIWSystem.ViewModel
{
    public class LogEntity
    {
        public string Sn { get; set; }
        public string PN { get; set; }
        public string Station { get; set; }
        public string UL { get; set; }
        public string LL { get; set; }
        public string TestValue { get; set; }
        public string Result { get; set; }
        public string Actor { get; set; }
        public string Source { get; set; }
        public string CreateAt { get; set; }
    }
    public class CSource
    {
        public string Name { get; set; }
    }
    public class TUNNINGInfoEntryViewModel : ViewModelBase
    {
        #region 属性
        private bool isFirstFilterStation = true;
        private bool isFirstFilterPN = true;
        private bool isFirstFilterTSource = true;
        private bool isFirstFilterResult = true;
        private bool isFirstFilterDefective = true;
        ObservableCollection<PartNumberEntity> backupPNs = null;
        ObservableCollection<StationsEntity> backupStations = null;
        ObservableCollection<CSource> backupTSource = null;
        ObservableCollection<TrackingEntity> backupResult = null;
        ObservableCollection<TrackingEntity> backupDefectives = null;

        //private ObservableCollection<PartNumberEntity> pns;
        ////机种信息
        //public ObservableCollection<PartNumberEntity> PNs
        //{
        //    get { return pns; }
        //    set { pns = value; this.RaisePropertyChanged(() => PNs); }
        //}
        //private PartNumberEntity selectedPartNumber;
        ///// <summary>
        ///// 选择的机种实体
        ///// </summary>
        //public PartNumberEntity SelectedPartNumber
        //{
        //    get { return selectedPartNumber; }
        //    set { selectedPartNumber = value; this.RaisePropertyChanged(() => SelectedPartNumber); }
        //}
        //private string pn;
        ///// <summary>
        ///// 机种
        ///// </summary>
        //public string PN
        //{
        //    get { return pn; }
        //    set { pn = value; this.RaisePropertyChanged(() => PN); }
        //}
        //private bool isOpenComboPNDropDown;
        ///// <summary>
        ///// 是否打开机种下拉框选项卡
        ///// </summary>
        //public bool IsOpenComboPNDropDown
        //{
        //    get { return isOpenComboPNDropDown; }
        //    set { isOpenComboPNDropDown = value; this.RaisePropertyChanged(() => IsOpenComboPNDropDown); }
        //}
        //private string searchPNText;
        ///// <summary>
        ///// 机种下拉框中输入的文本内容
        ///// </summary>
        //public string SearchPNText
        //{
        //    get { return searchPNText; }
        //    set { searchPNText = value; this.RaisePropertyChanged(() => SearchPNText); }
        //}
        private ObservableCollection<StationsEntity> stations;
        /// <summary>
        /// 站位信息
        /// </summary>
        public ObservableCollection<StationsEntity> Stations
        {
            get { return stations; }
            set { stations = value; this.RaisePropertyChanged(() => Stations); }
        }
        private string selectedStation;
        /// <summary>
        /// 选择的站位
        /// </summary>
        public string SelectedStation
        {
            get { return selectedStation; }
            set { selectedStation = value; this.RaisePropertyChanged(() => SelectedStation); }
        }
        private string station;
        /// <summary>
        /// 站位
        /// </summary>
        public string Station
        {
            get { return station; }
            set { station = value; this.RaisePropertyChanged(() => Station); }
        }
        private bool isOpenComboStationDropDown;
        /// <summary>
        /// 是否展开站位下拉列表框
        /// </summary>
        public bool IsOpenComboStationDropDown
        {
            get { return isOpenComboStationDropDown; }
            set { isOpenComboStationDropDown = value; this.RaisePropertyChanged(() => IsOpenComboStationDropDown); }
        }
        private string searchStationText;
        /// <summary>
        ///  站位下拉列表框搜索的文本
        /// </summary>
        public string SearchStationText
        {
            get { return searchStationText; }
            set { searchStationText = value; this.RaisePropertyChanged(() => SearchStationText); }
        }
        private ObservableCollection<CSource> tSources;
        //来源
        public ObservableCollection<CSource> TSources
        {
            get { return tSources; }
            set { tSources = value; this.RaisePropertyChanged(() => TSources); }
        }
        private CSource selectedTSource;
        //选择来源项
        public CSource SelectedTSource
        {
            get { return selectedTSource; }
            set { selectedTSource = value; this.RaisePropertyChanged(() => SelectedTSource); }
        }
        private string tSource;
        //选择来源值
        public string TSource
        {
            get { return tSource; }
            set { tSource = value; this.RaisePropertyChanged(() => TSource); }
        }
        private bool isOpenComboTSourceDropDown;
        //是否打开来源下拉列表框
        public bool IsOpenComboTSourceDropDown
        {
            get { return isOpenComboTSourceDropDown; }
            set { isOpenComboTSourceDropDown = value; this.RaisePropertyChanged(() => IsOpenComboTSourceDropDown); }
        }
        private string searchTSourceText;
        /// <summary>
        /// 来源下拉列表框搜索文本
        /// </summary>
        public string SearchTSourceText
        {
            get { return searchTSourceText; }
            set { searchTSourceText = value; this.RaisePropertyChanged(() => SearchTSourceText); }
        }
        private string sn;

        public string SN
        {
            get { return sn; }
            set { sn = value; this.RaisePropertyChanged(() => SN); }
        }
        private bool isFocusSn;
        /// <summary>
        /// 是否聚焦序列号输入文本框
        /// </summary>
        public bool IsFocusSn
        {
            get { return isFocusSn; }
            set { isFocusSn = value; this.RaisePropertyChanged(() => IsFocusSn); }
        }
        private ObservableCollection<TrackingCombineSnEntity> logs;

        public ObservableCollection<TrackingCombineSnEntity> Logs
        {
            get { return logs; }
            set { logs = value; this.RaisePropertyChanged(() => Logs); }
        }
        private ObservableCollection<TrackingEntity> results;
        /// <summary>
        /// 测试结果
        /// </summary>
        public ObservableCollection<TrackingEntity> Results
        {
            get { return results; }
            set { results = value; this.RaisePropertyChanged(() => Results); }
        }
        private TrackingEntity selectedResult;
        /// <summary>
        /// 选择的结果列表项
        /// </summary>
        public TrackingEntity SelectedResult
        {
            get { return selectedResult; }
            set { selectedResult = value; this.RaisePropertyChanged(() => SelectedResult); }
        }
        private string result;
        /// <summary>
        /// 选择的结果
        /// </summary>
        public string Result
        {
            get { return result; }
            set { result = value; this.RaisePropertyChanged(() => Result); }
        }
        private bool isOpenComboResultDropDown;
        /// <summary>
        /// 是否打开结果选择下拉框
        /// </summary>
        public bool IsOpenComboResultDropDown
        {
            get { return isOpenComboResultDropDown; }
            set { isOpenComboResultDropDown = value; this.RaisePropertyChanged(() => IsOpenComboResultDropDown); }
        }
        private string searchResultText;
        /// <summary>
        /// 查询的结果文本信息
        /// </summary>
        public string SearchResultText
        {
            get { return searchResultText; }
            set { searchResultText = value; this.RaisePropertyChanged(() => SearchResultText); }
        }
        private ObservableCollection<TrackingEntity> defectives;
        /// <summary>
        /// 不良描述
        /// </summary>
        public ObservableCollection<TrackingEntity> Defectives
        {
            get { return defectives; }
            set { defectives = value; this.RaisePropertyChanged(() => Defectives); }
        }
        private TrackingEntity selectedDefective;
        /// <summary>
        /// 选择的不良项
        /// </summary>
        public TrackingEntity SelectedDefective
        {
            get { return selectedDefective; }
            set { selectedDefective = value; this.RaisePropertyChanged(() => SelectedDefective); }
        }
        private string defective;
        /// <summary>
        /// 选择的不良值
        /// </summary>
        public string Defective
        {
            get { return defective; }
            set { defective = value; this.RaisePropertyChanged(() => Defective); }
        }
        private bool isOpenComboDefectiveDropDown;
        /// <summary>
        /// 是否打开不良下拉列表框选项卡
        /// </summary>
        public bool IsOpenComboDefectiveDropDown
        {
            get { return isOpenComboDefectiveDropDown; }
            set { isOpenComboDefectiveDropDown = value; this.RaisePropertyChanged(() => IsOpenComboDefectiveDropDown); }
        }
        private string searchDefectiveText;
        /// <summary>
        /// 搜索的不良项文本内容
        /// </summary>
        public string SearchDefectiveText
        {
            get { return searchDefectiveText; }
            set { searchDefectiveText = value; this.RaisePropertyChanged(() => SearchDefectiveText); }
        }


        #endregion

        #region 命令
        private RelayCommand loadPageCmd;

        public RelayCommand LoadPageCmd
        {
            get 
            {
                if (loadPageCmd == null)
                {
                    loadPageCmd = new RelayCommand(LoadedPage);
                }
                return loadPageCmd; 
            }
            set { loadPageCmd = value; }
        }

        //private RelayCommand filterPNCmd;

        //public RelayCommand FilterPNCmd
        //{
        //    get
        //    {
        //        if (filterPNCmd == null)
        //        {
        //            filterPNCmd = new RelayCommand(FilterPN);
        //        }
        //        return filterPNCmd;
        //    }
        //    set { filterPNCmd = value; }
        //}
        private RelayCommand filterStationCmd;

        public RelayCommand FilterStationCmd
        {
            get
            {
                if (filterStationCmd == null)
                {
                    filterStationCmd = new RelayCommand(FilterStation);
                }
                return filterStationCmd;
            }
            set { filterStationCmd = value; }
        }
        private RelayCommand filterTSourceCmd;

        public RelayCommand FilterTSourceCmd
        {
            get 
            {
                if (filterTSourceCmd==null)
                {
                    filterTSourceCmd = new RelayCommand(FilterTSource);
                }
                return filterTSourceCmd;
            }
            set { filterTSourceCmd = value; }
        }
        private RelayCommand snKeyEnterCommand;

        public RelayCommand SNKeyEnterCommand
        {
            get 
            {
                if (snKeyEnterCommand==null)
                {
                    snKeyEnterCommand = new RelayCommand(SNKeyEnterHandler);
                }
                return snKeyEnterCommand; 
            }
            set { snKeyEnterCommand = value; }
        }
        private RelayCommand entryCmd;

        public RelayCommand EntryCmd
        {
            get 
            {
                if (entryCmd==null)
                {
                    entryCmd = new RelayCommand(Entry);
                }
                return entryCmd; 
            }
            set { entryCmd = value; }
        }
        private RelayCommand filterResultCmd;

        public RelayCommand FilterResultCmd
        {
            get 
            {
                if (filterResultCmd==null)
                {
                    filterResultCmd = new RelayCommand(FilterResult);
                }
                return filterResultCmd; 
            }
            set { filterResultCmd = value; this.RaisePropertyChanged(() => FilterResultCmd); }
        }
        private RelayCommand filterDefectiveCmd;

        public RelayCommand FilterDefectiveCmd
        {
            get 
            {
                if (filterDefectiveCmd==null)
                {
                    filterDefectiveCmd = new RelayCommand(FilterDefective);
                }
                return filterDefectiveCmd; 
            }
            set { filterDefectiveCmd = value; }
        }
        private RelayCommand handleDefectiveContentCmd;

        public RelayCommand HandleDefectiveContentCmd
        {
            get 
            {
                if (handleDefectiveContentCmd == null)
                {
                    handleDefectiveContentCmd = new RelayCommand(HandleDefectiveContent);
                }
                return handleDefectiveContentCmd; 
            }
            set { handleDefectiveContentCmd = value; }
        }
        #endregion

        #region 方法
        //页面加载
        private void LoadedPage()
        {
            //FillPNsToComboBoxAsync();
            Stations = new ObservableCollection<StationsEntity>();
            string[] arrayStations = Global.AppConfigs.TunningInfo.Station.Split('|');
            for (int i = 0; i < arrayStations.Length; i++)
            {
                Stations.Add(new StationsEntity { Station = arrayStations[i] });
            }
            TSources = new ObservableCollection<CSource>();
            string[] arraySources = Global.AppConfigs.TunningInfo.Source.Split('|');
            for (int i = 0; i < arraySources.Length; i++)
            {
                TSources.Add(new CSource { Name = arraySources[i] });
            }
            Results = new ObservableCollection<TrackingEntity>();
            Results.Add(new TrackingEntity { Result = "PASS" });
            Results.Add(new TrackingEntity { Result = "FAIL" });
            Defectives = new ObservableCollection<TrackingEntity>();
            string[] arrayDefectives = Global.AppConfigs.TunningInfo.Defective.Split('|');
            for (int i = 0; i < arrayDefectives.Length; i++)
            {
                Defectives.Add(new TrackingEntity { FailDescription = arrayDefectives[i] });
            }
        }
        /// <summary>
        /// 填充机种信息到下拉列表框中
        /// </summary>
        //private async void FillPNsToComboBoxAsync()
        //{
        //    DataTable dtPNs = new DataTable();
        //    dtPNs = BusinessProcess.GetPNs(EnumPNType.All);
        //    ObservableCollection<PartNumberEntity> tmpPNs = new ObservableCollection<PartNumberEntity>();
        //    PNs = new ObservableCollection<PartNumberEntity>();
        //    await Task.Run(() => {
        //        for (int i = 0; i < dtPNs.Rows.Count; i++)
        //        {
        //            tmpPNs.Add(new PartNumberEntity
        //            {
        //                PN = dtPNs.Rows[i]["PartNumber"].ToString()
        //            });
        //        }
        //        System.Windows.Application.Current.Dispatcher.BeginInvoke((Action)(() => {
        //            PNs = tmpPNs;
        //        }));
        //    });
        //}
        /// <summary>
        /// 筛选机种下拉列表框中的数据
        /// </summary>
        //private void FilterPN()
        //{

        //    IsOpenComboPNDropDown = true;
        //    //当是第一次过滤的时候备份原始数据
        //    //这样是为了当不输入搜索条件时添加原始数据到列表中
        //    //当输入搜索条件时生成过滤集合绑定当下拉列表中
        //    if (isFirstFilterPN)
        //    {
        //        backupPNs = new ObservableCollection<PartNumberEntity>();
        //        backupPNs = PNs;
        //        isFirstFilterPN = false;
        //    }
        //    if (!string.IsNullOrEmpty(SearchPNText))
        //    {
        //        IEnumerable<PartNumberEntity> partNumberEntities = PNs.Where(s => s.PN.ToUpper().Contains(SearchPNText.ToUpper()));
        //        PNs = new ObservableCollection<PartNumberEntity>();
        //        foreach (var p in partNumberEntities)
        //        {
        //            PNs.Add(p);
        //        }
        //    }
        //    else
        //    {
        //        PNs = backupPNs;
        //    }

        //}
        /// <summary>
        /// 筛选站位下拉列表框中的数据
        /// </summary>
        private void FilterStation()
        {
            IsOpenComboStationDropDown = true;
            //当是第一次过滤的时候备份原始数据
            //这样是为了当不输入搜索条件时添加原始数据到列表中
            //当输入搜索条件时生成过滤集合绑定当下拉列表中
            if (isFirstFilterStation)
            {
                backupStations = new ObservableCollection<StationsEntity>();
                backupStations = Stations;
                isFirstFilterStation = false;
            }
            if (!string.IsNullOrEmpty(SearchStationText) && Stations != null)
            {
                IEnumerable<StationsEntity> stations = Stations.Where(s => s.Station.ToUpper().Contains(SearchStationText.ToUpper()));
                Stations = new ObservableCollection<StationsEntity>();
                foreach (var s in stations)
                {
                    Stations.Add(s);
                }
            }
            else
            {
                Stations = backupStations;
            }

        }

        private void FilterDefective()
        {

            IsOpenComboDefectiveDropDown = true;
            //当是第一次过滤的时候备份原始数据
            //这样是为了当不输入搜索条件时添加原始数据到列表中
            //当输入搜索条件时生成过滤集合绑定当下拉列表中
            if (isFirstFilterDefective)
            {
                backupDefectives = new ObservableCollection<TrackingEntity>();
                backupDefectives = Defectives;
                isFirstFilterDefective = false;
            }
            if (!string.IsNullOrEmpty(SearchDefectiveText) && Defectives != null)
            {
                IEnumerable<TrackingEntity> defectives = Defectives.Where(s => s.FailDescription.ToUpper().Contains(SearchDefectiveText.ToUpper()));
                Defectives = new ObservableCollection<TrackingEntity>();
                foreach (var d in defectives)
                {
                    Defectives.Add(d);
                }
            }
            else
            {
                Defectives = backupDefectives;
            }
        }

        /// <summary>
        /// 筛选来源下拉列表框中的数据
        /// </summary>
        private void FilterTSource()
        {
            IsOpenComboTSourceDropDown = true;
            //当是第一次过滤的时候备份原始数据
            //这样是为了当不输入搜索条件时添加原始数据到列表中
            //当输入搜索条件时生成过滤集合绑定当下拉列表中
            if (isFirstFilterTSource)
            {
                backupTSource = new ObservableCollection<CSource>();
                backupTSource = TSources;
                isFirstFilterTSource = false;
            }
            if (!string.IsNullOrEmpty(SearchTSourceText) && TSources != null)
            {
                IEnumerable<CSource> sources = TSources.Where(s => s.Name.ToUpper().Contains(SearchTSourceText.ToUpper()));
                TSources = new ObservableCollection<CSource>();
                foreach (var s in sources)
                {
                    TSources.Add(s);
                }
            }
            else
            {
                TSources = backupTSource;
            }

        }
        /// <summary>
        /// 过滤结果信息
        /// </summary>
        private void FilterResult()
        {
            IsOpenComboResultDropDown = true;
            //当是第一次过滤的时候备份原始数据
            //这样是为了当不输入搜索条件时添加原始数据到列表中
            //当输入搜索条件时生成过滤集合绑定当下拉列表中
            if (isFirstFilterResult)
            {
                backupResult = new ObservableCollection<TrackingEntity>();
                backupResult = Results;
                isFirstFilterResult = false;
            }
            if (!string.IsNullOrEmpty(SearchResultText) && Results != null)
            {
                IEnumerable<TrackingEntity> result = Results.Where(s => s.Result.ToUpper().Contains(SearchResultText.ToUpper()));
                Results = new ObservableCollection<TrackingEntity>();
                foreach (var r in result)
                {
                    Results.Add(r);
                }
            }
            else
            {
                Results = backupResult;
            }
        }
        /// <summary>
        /// 序列号回车事件处理
        /// </summary>
        private void SNKeyEnterHandler()
        {
            bool isOk = false;
            isOk = CheckSnInfo();
            if (isOk)
                Entry();
            IsFocusSn = true;
        }

        private void Entry()
        {
            string startTime = string.Empty;
            string retMsg = string.Empty;//数据库返回的状态码和状态信息
            string[] arrayMsg = new string[2]; //截取返回的状态码和状态信息
            TrackingEntity trackingEntity = new TrackingEntity();
            DataTable dtTracking = new DataTable();
            
            if (!CheckUIInputInfo())
                return;
            startTime = DateTime.Now.ToString();
            trackingEntity.Sn = this.SN.ToUpper();
            trackingEntity.Station = this.Station == "初调" ? "TUNNING1" : "TUNNING";// "TUNNING";
            trackingEntity.Result = this.Result.ToUpper();
            trackingEntity.EquipmentName = Environment.MachineName;
            trackingEntity.StartTime = startTime;
            trackingEntity.StopTime = DateTime.Now.ToString();
            trackingEntity.Actor = LogInInfo.User;
            trackingEntity.TunningInfo = new TunningEntity { Station = this.Station ?? "", Source = this.TSource ??"",Defective=this.Defective ??"" };
            //trackingEntity.TunningInfo.Station = this.SearchStationText;
            //trackingEntity.TunningInfo.Source = this.TSource;
            //retMsg = "OK|插入成功!"; --用于调试使用
            retMsg = BusinessProcess.AddEndTracking(trackingEntity, out dtTracking);
            arrayMsg = retMsg.Split('|');
            if (arrayMsg[0] == "OK")
            {
                //首次添加要初始化Log集合
                if (Logs == null)
                    Logs = new ObservableCollection<TrackingCombineSnEntity>();
                Logs.Add(new TrackingCombineSnEntity
                {
                    Sn = trackingEntity.Sn,
                    PN = BusinessProcess.GetPNBySn(trackingEntity.Sn),
                    Station = this.Station == "初调" ? "TUNNING1" : "TUNNING",// "TUNNING",
                    EquipmentName = Environment.MachineName,
                    Result = trackingEntity.Result,
                    Actor = LogInInfo.User,
                    TunningInfo = new TunningEntity { Station = this.Station ?? "", Source = this.TSource ?? "", Defective = this.Defective ?? "" },
                    CreateAt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                });
                //Logs = new ObservableCollection<TrackingCombineSnEntity>();
                //for (int i = 0; i < dtTracking.Rows.Count; i++)
                //{
                //    Logs.Add(new TrackingCombineSnEntity
                //    {
                //        Sn = dtTracking.Rows[i]["Sn"].ToString() ?? "",
                //        PN = BusinessProcess.GetPNBySn(dtTracking.Rows[i]["Sn"].ToString() ?? ""),
                //        WO = dtTracking.Rows[i]["WO"].ToString() ?? "",
                //        Station = dtTracking.Rows[i]["Station"].ToString() ?? "",
                //        Result = dtTracking.Rows[i]["Result"].ToString() ?? "",
                //        FailDescription = dtTracking.Rows[i]["FailDescription"].ToString() ?? "",
                //        FailValue = dtTracking.Rows[i]["FailValue"].ToString() ?? "",
                //        EquipmentName = dtTracking.Rows[i]["EquipmentName"].ToString() ?? "",
                //        TestSequence = dtTracking.Rows[i]["TestSequence"].ToString() ?? "",
                //        Duration = dtTracking.Rows[i]["Duration"].ToString() ?? "",
                //        Shift = dtTracking.Rows[i]["Shift"].ToString() ?? "",
                //        Actor = dtTracking.Rows[i]["Actor"].ToString() ?? "",
                //        CreateAt = dtTracking.Rows[i]["CreateAt"].ToString() ?? ""
                //    }) ;
                //}
                //根据时间进行降序排序，便于将最近一条记录显示再最上面。
                //根据时间进行降序排序，便于将最近一条记录显示再最上面。
                var a = Logs.OrderByDescending(x => Convert.ToDateTime(x.CreateAt)).ToList();
                Logs = new ObservableCollection<TrackingCombineSnEntity>();
                for (int i = 0; i < a.Count; i++)
                {
                    Logs.Add(new TrackingCombineSnEntity
                    {
                        Sn = a[i].Sn ?? "",
                        PN = a[i].PN ?? "",
                        Station = a[i].Station ?? "",
                        EquipmentName = a[i].EquipmentName ?? "",
                        Result = a[i].Result ?? "",
                        Actor = a[i].Actor ?? "",
                        TunningInfo = new TunningEntity { Station = a[i].TunningInfo?.Station ?? "", Source = a[i].TunningInfo?.Source ?? "", Defective =a[i].TunningInfo?.Defective ?? "" },
                        CreateAt = a[i].CreateAt ?? "",
                    });
                }
                //var a = Logs.OrderByDescending(x => Convert.ToDateTime(x.CreateAt)).ToList();
                //Logs = new ObservableCollection<TrackingCombineSnEntity>();
                //for (int i = 0; i < a.Count; i++)
                //{
                //    Logs.Add(new TrackingCombineSnEntity
                //    {
                //        Sn = a[i].Sn ?? "",
                //        PN=a[i].PN??"",
                //        WO = a[i].WO ?? "",
                //        Station =a[i].Station ?? "",
                //        Result =a[i].Result ?? "",
                //        FailDescription =a[i].FailDescription ?? "",
                //        FailValue = a[i].FailValue ?? "",
                //        EquipmentName = a[i].EquipmentName ?? "",
                //        TestSequence = a[i].TestSequence ?? "",
                //        Duration = a[i].Duration ?? "",
                //        Shift = a[i].Shift ?? "",
                //        Actor = a[i].Actor ?? "",
                //        CreateAt = a[i].CreateAt ?? ""
                //    });
                //}
                //Logs.Add(new LogEntity
                //{
                //    Sn = this.SN.ToUpper() ?? "",
                //    PN = this.PN.ToUpper() ?? "",
                //    Station = this.SearchStationText.ToUpper() ?? "",
                //    Result = trackingEntity.Result,
                //    Actor = LogInInfo.User,
                //    Source = this.TSource,
                //    CreateAt = DateTime.Now.ToString("yyyyMMdd HH:mm:ss")
                //});
                this.SN = "";
                //this.AddPieSeriesData();//刷新饼形图
            }
            else
            {
                MessageBox.Show(arrayMsg[1], "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        /// <summary>
        /// 检查录入的序列号信息
        /// </summary>
        /// <returns></returns>
        private bool CheckSnInfo()
        {
            //string pn = string.Empty;//机种
            if (string.IsNullOrEmpty(this.SN))
            {
                MessageBox.Show("序列号信息不能为空,请输入序列号信息.", "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return false;
            }
            if (!BusinessProcess.SNIsExists(this.SN))
            {
                MessageBox.Show("序列号【" + this.SN + "】在系统中不存在,请重新输入.", "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return false;
            }
            //pn = BusinessProcess.SnOwnerPN(this.SN);
            //if (pn != this.PN)
            //{
            //    MessageBox.Show("序列号【" + this.SN + "】不属于机种【" + this.PN + "】.请检查序列号信息是否正确？", "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Warning);
            //    return false;
            //}
            return true;
        }
        /// <summary>
        /// 检查UI界面输入的参数信息
        /// </summary>
        /// <returns></returns>
        private bool CheckUIInputInfo()
        {
            string station = string.Empty, source = string.Empty,result=string.Empty;
            //pn = this.PN ?? "";
            station = this.Station ?? "";
            source = this.TSource ?? "";
            result = Result ?? "";
            //if (string.IsNullOrEmpty(pn))
            //{
            //    MessageBox.Show("机种信息不能为空,请选择机种信息.", "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Warning);
            //    return false;
            //}
            if (string.IsNullOrEmpty(station))
            {
                MessageBox.Show("站位信息不能为空,请选择站位信息.", "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return false;
            }
            if (string.IsNullOrEmpty(source))
            {
                MessageBox.Show("来源信息不能为空,请选择来源信息.", "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return false;
            }
            if (string.IsNullOrEmpty(result))
            {
                MessageBox.Show("结果信息不能为空,请选择来源信息.", "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                return false;
            }
            return CheckSnInfo();
        }
        /// <summary>
        /// 根据结果处理不良项内容《当选择结果是PASS时清空不良项内容》
        /// </summary>
        private void HandleDefectiveContent()
        {
            if (this.Result=="PASS")
            {
                this.SearchDefectiveText = "";
            }
        }

        #endregion
    }
}
